package yxy.cherry.battle.module.affix.buff;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.PropertyData;
import yxy.cherry.battle.module.PropertyType;
import yxy.cherry.battle.module.affix.AffixFactory;
import yxy.cherry.battle.module.affix.Buff;
import yxy.cherry.battle.module.affix.BuffType;
import yxy.cherry.battle.module.record.stream.RecordStream39ChangeAttribute;
import yxy.cherry.data.bean.skill;

/**
 * @author James
 * 破甲（降低对方的物理和法术防御）
 * @date 2022/2/24 12:01
 **/
@BuffType(Type = AffixFactory.BuffTypeEnum.破甲)
public class Affix69ArmorBreak extends Buff {
    private PropertyType getArmorBreakType1() { return PropertyType.forNumber(getParam(0)); }

    private int getArmorBreakPer1() { return getParam(1); }

    private PropertyType getArmorBreakType2() { return PropertyType.forNumber(getParam(2)); }

    private int getArmorBreakPer2() { return getParam(3); }

    public Affix69ArmorBreak(Fighter source, Fighter target, skill skilldata, int[] params) {
        super(source, target, skilldata, params);
    }

    @Override
    public boolean exec(Fighter source, Fighter target) {
        PropertyType type1 = getArmorBreakType1();
        PropertyType type2 = getArmorBreakType2();

        PropertyData propertyData = new PropertyData();
        boolean set = false;
        int type1Number = 0;
        int type2Number = 0;
        long reduceValue1 = 0;
        long reduceValue2 = 0;
        if(type1 != null && getArmorBreakPer1() > 0){
            type1Number = type1.getNumber();
            reduceValue1 = target.getData().getPropertyData().getValue(type1) * getArmorBreakPer1() / VALUE_比率分母;
            propertyData.setValue(type1, -reduceValue1);
            set = true;
        }

        if(type2 != null && getArmorBreakPer2() > 0){
            type2Number = type2.getNumber();
            reduceValue2 = target.getData().getPropertyData().getValue(type2) * getArmorBreakPer2() / VALUE_比率分母;
            propertyData.setValue(type2, -reduceValue2);
            set = true;
        }
        if(set){
            setPropertyData(propertyData);
        }
        getRecord().stream(new RecordStream39ChangeAttribute(target, this, type1Number, reduceValue1, type2Number, reduceValue2)).record();
        Battle.battleLogger(6,"虚弱：施法者"+source.getName()+"对"+target.getName()+"附加破甲，降低"+type1+":"+reduceValue1+":"+type2+":"+reduceValue2);

        return true;
    }

    @Override
    public BuffType getBuffType() {
        return BuffType.减益效果;
    }

    @Override
    public BuffStateType getBuffStateType() {return BuffStateType.armorBreakState;}
}
